package ICM.server;

import java.util.ArrayList;

/**
 * This class checks each user in the ConnectedUsers array and remove the users that are disconnected from the server,
 * in other words, this class is for keeping the ConnectedUsers array updated when users didn't properly logout from the system.
 */
public class CheckUser extends Thread {
	
	public CheckUser()
	{
		//
	}
	
	public void run()
	{
		ArrayList<ConnectedClient> ConnectedUsers = null;
		while (true)
		{
			synchronized(this)
			{
				ConnectedUsers = Server.ConnectedUsers;
				if (ConnectedUsers!=null)
					for (int i = 0; i<ConnectedUsers.size();i++)
						if (!ConnectedUsers.get(i).getClient().isAlive())
						{
							ConnectedUsers.remove(i);
							Server.ConnectedUsers=ConnectedUsers;
						}
				try {
					sleep(200);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}

}